package com.changzhi.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.changzhi.common.constants.RedisConstants;
import com.changzhi.ldyl.model.SysDict;
import com.changzhi.mapper.SysDictMapper;
import com.changzhi.service.SysDictService;
import com.changzhi.util.RedisUtil;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.Map;

/**
 * <p>
 * 系统字典表 服务实现类
 * </p>
 *
 * @author Alfred
 * @since 2019-11-26
 */
@Service
public class SysDictServiceImpl extends ServiceImpl<SysDictMapper, SysDict> implements SysDictService {

    @Resource
    private RedisUtil redisUtil;

    @Override
    public SysDict getSysDictByCache(String code,Long time) {
        SysDict sysDict = (SysDict) redisUtil.get(RedisConstants.SYSTEM_PARAM_CONFIG + code);
        if (sysDict == null) {
            sysDict = baseMapper.selectOne(new QueryWrapper<SysDict>().eq(SysDict.CODE, code).last("limit 1"));
            redisUtil.set(RedisConstants.SYSTEM_PARAM_CONFIG + code, sysDict, time);
        }
        return sysDict;
    }
}
